<%request.setAttribute("pageName",new String("gadgets"));%><%@include file="/include/header.jsp" %>
<%
	if(request.getParameter("gname")== null || request.getParameter("gname").isEmpty())
		response.sendRedirect("/index.jsp");
	
   	PersistenceManager pm = PMF.get().getPersistenceManager();
    Query query = pm.newQuery(Gadget.class);
    query.setFilter("name == nameParam");
    query.declareParameters("String nameParam");
    query.setUnique(true); 
    String title ="";
    try 
    {
	    Gadget g  = (Gadget) query.execute(request.getParameter("gname"));
	    if(g != null && g.isVisible())
	    {
	    	
	    	if(g.getTitle()!=null && !g.getTitle().isEmpty())
        		title = g.getTitle();
        	else
        		title = g.getName();
		    %>
		    <table>
	        <tr valign="top"><td width='30%' colspan='2'><h2><%=title%></h2>
	         
	         <tr valign="top"><td width='30%' >
	         	<img src="<%=UrlUtils.getGadgetHome(g.getName())%>screenshot.png">   	
	      	</td>
	       	<td> 
	       			
	        <% 
	      
	        if(g.getDescription()!=null && !g.getDescription().isEmpty())
       			out.print(g.getDescription());
	        
	        %>
	        
        	</td></tr>
          	
           <tr><td></td><td>
           	<%
	      	if(g.getType()==SharedConstants.gadgetGoogleTypeiGoogle)
	      		out.print("<a href=\"http://fusion.google.com/add?source=atgs&moduleurl="+UrlUtils.getGadgetXMLUrl(request, g.getName(), g.getGadgetFileName())+"\"><img src='http://gmodules.com/ig/images/plus_google.gif' border=\"0\" alt=\"Add to iGoogle\"></a><br>");
        	if(DomainUserUtils.isOpenIdUserAdmin())
        	{
        		if(g.getStatus()!= SharedConstants.gadgetStatusOnLine)
					out.println("<font color=\"red\">This Gadget is NOT online<font>");
							
				if(g.getStatus()== SharedConstants.gadgetStatusOnLine)
					out.println("<a href='/admin/setOffline.jsp?gname="+g.getName()+"'> <img src=\"/static/icons/arrowDown.gif\" alt=\"Off Line\"/> </a>");
				if(g.getStatus()== SharedConstants.gadgetStatusOffLine || g.getStatus()== SharedConstants.gadgetStatusTest)
					out.println("<a href='/admin/setOnLine.jsp?gname="+g.getName()+"'> <img src=\"/static/icons/arrowUp.gif\" alt=\"On Line\"/> </a>");
				out.println("<a href='/admin/addEditGadget.jsp?gname="+g.getName()+"'> Edit </a>");
		   	}
	      	%>
	      	</td></tr>
           <tr><td colspan=2><textarea cols="80"><%=UrlUtils.getGadgetXMLUrl(request, g.getName(), g.getGadgetFileName())%></textarea></td></tr>
              
         </table><% 
     	} 
     }
      finally 
    {
        query.closeAll();
        pm.close();
    }
   %><%@include file="/include/footer.jsp" %>